package org.ysu;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

@SpringBootApplication
@MapperScan("org.ysu.mapper")
public class Main {
    public static void main(String[] args) {
        SpringApplication.run(Main.class,args);
    }


    /**
     * 配置解决跨域的过滤器
     */
    @Bean
    public CorsFilter getCorsFilter() {
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        // 允许请求中携带哪些请求头信息跨域
        corsConfiguration.addAllowedHeader("*");
        // 允许哪些请求方式跨域
        corsConfiguration.addAllowedMethod("*");
        // 允许哪些域名进行跨域
        corsConfiguration.addAllowedOrigin("*");
        // 配置解决跨域过滤器的拦截路径
        source.registerCorsConfiguration("/**", corsConfiguration);
        CorsFilter filter = new CorsFilter(source);
        return filter;
    }
}